// packageD/auction/auction-mine/my_auction/my_auction.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.id){
      this.setData({
        active:options.id
      });
    }
    this.getSearch();
  },
  goxiangq(e){
    console.log(e.currentTarget.dataset.goodid.goods_id);
    wx.navigateTo({
      url: '/packageD/auction/auction/auction_good/auction_good?id='+e.currentTarget.dataset.goodid.goods_id,
    });
  },
  toBuy(e){
    let item = e.currentTarget.dataset.item;
    console.log(item,'ddddddd')
    wx.navigateTo({
      url: '/packageD/buy/myOrder_v2/myOrder_v2?goodsId='+item.goods_id+'&tag=auction&total=1&fixed_price=0&auction_sn='+ item.auction_sn,
    });
  },
  itemClick(e){
    this.setData({
      active:e.detail.index
    });
    this.getSearch();
  },
  getSearch(){
    this.setData({
      page:1
    });
    var that = this;
    var urlStr = "";
    if(that.data.active == 0){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.prepayment');
    }else if(that.data.active == 1){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.biding');
    }else if(that.data.active == 2){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.bide');
    }else if(that.data.active == 3){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.finish');
    }else if(that.data.active == 4){

      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=auction',
        success(){
          wx.showLoading({
            title: '加载中',
            icon:'none',
            duration:1000
          });
        }
      });
    }
    app._postNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            datas: res.data.data,
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.current_page >= this.data.last_page){
      wx.showToast({
        title: '暂无更多',
        icon:'none',
        duration:1000
      });
    }else{
      let pages = this.data.page +1;
      this.setData({
        page:pages
      });
      this.getNext();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getNext() {
    var that = this;
    var urlStr = "";
    if(that.data.active == 0){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.prepayment');
    }else if(that.data.active == 1){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.biding');
    }else if(that.data.active == 2){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.bide');
    }else if(that.data.active == 3){
      urlStr = app.getNetAddresss('plugin.auction.api.bid-order.finish');
    }else if(that.data.active == 4){
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?status=0',
      });
    }
    app._postNetWork({
      url: urlStr,
      data:{
        page:that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            datas: that.data.datas.concat(res.data.data),
            current_page:res.data.current_page,
            last_page:res.data.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
});
